package com.gnerv.cms.controller;

import com.gnerv.cms.common.Result;
import com.gnerv.cms.dto.SiteDTO;
import com.gnerv.cms.dto.SiteSaveDTO;
import com.gnerv.cms.dto.SiteSearchDTO;
import com.gnerv.cms.service.ISiteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 基础平台-站点表 前端控制器
 * </p>
 *
 * @author Gnerv LiGen
 * @since 2019-10-10
 */
@Api(tags = "站点管理")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/cms/site")
public class SiteController {

    @Resource
    private ISiteService siteService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result saveSite(@RequestBody SiteSaveDTO siteSaveDTO) {
        siteService.saveSite(siteSaveDTO);
        return Result.response();
    }

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result createSite(@RequestBody SiteSaveDTO siteSaveDTO) {
        siteService.createSite(siteSaveDTO);
        return Result.response();
    }

    @RequestMapping(value = "/delete/{siteId}", method = RequestMethod.POST)
    public Result deleteSite(@PathVariable(value = "siteId") String siteId) {
        siteService.deleteSite(siteId);
        return Result.response();
    }

    @RequestMapping(value = "/update/", method = RequestMethod.POST)
    public Result updateSite(@RequestBody SiteSaveDTO siteSaveDTO) {
        siteService.updateSite(siteSaveDTO);
        return Result.response();
    }

    @RequestMapping(value = "/{siteId}/status/{status}", method = RequestMethod.GET)
    public Result updateSiteStatus(@PathVariable(value = "siteId") String siteId,
                                   @PathVariable(value = "status") Integer status) {
        siteService.updateSiteStatus(siteId, status);
        return Result.response();
    }

    @RequestMapping(value = "/select/{siteId}", method = RequestMethod.POST)
    public Result selectSite(@PathVariable(value = "siteId") String siteId) {
        siteService.selectSite(siteId);
        return Result.response();
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result listSite(SiteSearchDTO siteSearchDTO) {
        List<SiteDTO> sites = siteService.listSite(siteSearchDTO);
        return Result.response().data("sites", sites);
    }

}
